package action.listener;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;

import engine.Vertex;
import gui.View;

public class DrawEdge implements MouseListener
{
   private Random random = new Random();
   private Vertex start=null, end;
   private View view;
   private int x, y;
   public DrawEdge(View view)
   {
      super();
      this.view = view;
   }

   @Override
   public void mouseClicked(MouseEvent e)
   {
      // TODO Auto-generated method stub
   }

   @Override
   public void mouseEntered(MouseEvent e)
   {
      // TODO Auto-generated method stub
      x = e.getX();
      y = e.getY();



   }

   @Override
   public void mouseExited(MouseEvent e)
   {
      // TODO Auto-generated method stub

   }

   @Override
   public void mousePressed(MouseEvent e)
   {
      // TODO Auto-generated method stub
      x = e.getX();
      y = e.getY();
      int weight = 0;

      if(start==null)
      {
         int i = view.isVertex(x, y);
         if(i>=0)
            start=view.getVertices().get(i);
      }
      else
      {
         int i = view.isVertex(x, y);
         if(i>=0)
         {
            end=view.getVertices().get(i);
            weight = random.nextInt(99);
            if(end!=start)
               view.addEdge(start, end, weight);
            view.repaint();
         }
         start=null;
      }

   }

   @Override
   public void mouseReleased(MouseEvent e)
   {
      // TODO Auto-generated method stub

   }

}
